package com.drugStorage.struts.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.drugStorage.domain.DrugScience;
import com.drugStorage.domain.DrugSupplier;
import com.drugStorage.hibernate.dao.DrugScienceDao;
import com.drugStorage.spring.service.DrugSupplierService;

public class DrugScienceAction extends DispatchAction {

	private DrugScienceDao drugScienceDao;

	public DrugScienceDao getDrugScienceDao() {
		return drugScienceDao;
	}

	public void setDrugScienceDao(DrugScienceDao drugScienceDao) {
		this.drugScienceDao = drugScienceDao;
	}

	@Override
	protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	
		BeanFactory factory = new ClassPathXmlApplicationContext(
		"applicationContext-*.xml");
drugScienceDao = (DrugScienceDao) factory
		.getBean("drugScienceDao");

List<DrugScience> drugList = drugScienceDao.getDrugList();

request.setAttribute("drugList", drugList);
return mapping.findForward("Show_DrugList");
		
	}
	public ActionForward GoAddDrug(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		BeanFactory factory = new ClassPathXmlApplicationContext(
				"applicationContext-*.xml");
		drugScienceDao = (DrugScienceDao) factory
				.getBean("drugScienceDao");



		return mapping.findForward("Go_Add_Drug");
	}

	protected ActionForward AddDrug(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BeanFactory factory = new ClassPathXmlApplicationContext(
		"applicationContext-*.xml");
drugScienceDao = (DrugScienceDao) factory
		.getBean("drugScienceDao");

BeanUtils.copyProperties(dest, orig)
		
		
		
		return super.unspecified(mapping, form, request, response);
	}
	protected ActionForward UnuserdDrug(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	
		return super.unspecified(mapping, form, request, response);
	}
	
	
	
}
